<?php

	class Article extends AbstractMVCController {
		
		protected
			$arrURLParts = array('articleID'),
			$sViewClass = 'SimpleView',
			$bTranslateOutput = true,
			$bAutoloadModel = true;
		
		
		public function display(Request $objRequest, TekunaView $objView) {

			// get the article's ID from the URL
			$arrURLParts = $this -> getApplicationContext() -> getURLInformation() -> getMatchedURLParts();
			$iArticleID = (int) $arrURLParts['articleID'];
			
			// load the model
			$objModel = $this -> getModel();
			$objModel -> loadArticle($iArticleID);
			
			// assign the article data to the view
			$objView -> assign('date', date('Y-m-d H:i:s', $objModel -> date));
			$objView -> assign('title', $objModel -> title);
			$objView -> assign('text', $objModel -> text);
		}
		
		
		public function error(Request $objRequest, TekunaView $objView, Exception $objException) {
			
			$objView -> setTemplate('Error.tpl');
			$objView -> assign('message', $objException -> getMessage());
			
			// log exception unless it is an ArticleModelException
			if (! $objException instanceof ArticleModelException) {
				
				log_exception($objException);
			}
		}
	}